package com.itheima.blog.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.blog.admin.dto.PageDto;
import com.itheima.blog.admin.entity.TBanner;
import com.itheima.blog.admin.domain.po.TWebNavbar;
import com.itheima.blog.admin.dao.TWebNavbarMapper;
import com.itheima.blog.admin.service.ITWebNavbarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.blog.admin.vo.PageVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 门户网站首页导航栏 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-07-13
 */
@Service
@RequiredArgsConstructor
public class TWebNavbarServiceImpl extends ServiceImpl<TWebNavbarMapper, TWebNavbar> implements ITWebNavbarService {

    private final TWebNavbarMapper tWebNavbarMapper;
    @Override
    public void insertRoute(TWebNavbar tWebNavbar) {
        LocalDateTime now = LocalDateTime.now();
        tWebNavbar.setCreateTime(now);
        save(tWebNavbar);
    }

    @Override
    public void updateRoute(TWebNavbar tWebNavbar,Integer routeId) {
        tWebNavbar.setId(routeId);
        updateById(tWebNavbar);
    }

    @Override
    public void deleteRoute(Integer routeId) {
        removeById(routeId);
    }

    @Override
    public PageVO<TWebNavbar> selectAll(PageDto pageDto) {
        PageVO<TWebNavbar> pageVO = new PageVO<>();
        IPage<TWebNavbar> tBannerIPage = lambdaQuery().eq(TWebNavbar::getIsShow,true)
                .orderByAsc(TWebNavbar::getSort)
                .page(new Page<>()).setPages(pageDto.getPageNo()).setSize(pageDto.getPageSize());

        pageVO.setList(tBannerIPage.getRecords());
        pageVO.setPages(tBannerIPage.getPages());
        pageVO.setTotal(tBannerIPage.getTotal());

        return pageVO;
    }
}
